#include "control.h"
#include "stdio.h"
#include <strsafe.h>

int	controlpanelwidth = 550;

COLORREF RED = RGB(255, 160, 122);
COLORREF GREEN = RGB(144, 238, 144);
HPEN redpen = CreatePen(PS_SOLID, 1, RED);
HPEN greenpen = CreatePen(PS_SOLID, 1, GREEN);
HBRUSH redBrush = CreateSolidBrush(RED);
HBRUSH greenBrush = CreateSolidBrush(GREEN);
//scroll bar limit
int scrollLim = 100;
//create required fonts
HFONT title_Font = NULL;
HFONT *label_Font = &title_Font;
HFONT *button_Font = &title_Font;
BOOL g_bOpaque = FALSE;
COLORREF g_rgbText = RGB(0, 0, 0);
COLORREF g_rgbBackground = RGB(255, 255, 255);
int LEFT = 1;
int CENTER = 2;
int RIGHT = 3;
void DrawMessage(HDC hdc, RECT* prc, HFONT hf, char szTitle[], int alignment)
{
	HFONT hfOld = (HFONT)SelectObject(hdc, hf);

	//SetBkColor(hdc, g_rgbBackground);
	SetTextColor(hdc, g_rgbText);

	if(g_bOpaque)
	{
		SetBkMode(hdc, OPAQUE);
	}
	else
	{
		SetBkMode(hdc, TRANSPARENT);
	}

	if (alignment == 1)
		DrawText(hdc, szTitle, -1, prc, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
	if (alignment == 2)
		DrawText(hdc, szTitle, -1, prc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	if (alignment == 3)
		DrawText(hdc, szTitle, -1, prc, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);

	SelectObject(hdc, hfOld);
}
void DrawRotateMessage(HDC hdc, RECT* rc, HFONT hfnt, LPSTR lpszRotate,  int angle = 0)  
 {  
	HFONT hfntPrev; 
	hfntPrev = hfnt;
	HRESULT hr; 
	size_t pcch;
	 
	// Allocate memory for a LOGFONT structure. 
	 
	PLOGFONT plf = (PLOGFONT) LocalAlloc(LPTR, sizeof(LOGFONT)); 
	 
	 
	// Specify a font typeface name and weight. 
	 
	hr = StringCchCopy(plf->lfFaceName, 5, "Arial");
	//if (FAILED(hr))
	//{
	//// TODO: write error handler
	//}

	plf->lfWeight = FW_NORMAL; 
	 
	// Set the background mode to transparent for the 
	// text-output operation. 
	 
	SetBkMode(hdc, TRANSPARENT); 
	 
	// Draw the string 35 times, rotating 10 degrees 
	// counter-clockwise each time. 
	 
	//for (angle = 0; angle < 3500; angle += 100) 
	//{
		angle = angle*10;
		plf->lfEscapement = angle; 
		hfnt = CreateFontIndirect(plf); 
		hfntPrev = (HFONT) SelectObject(hdc,  hfnt);
		
		//
		// The StringCchLength call is fitted to the lpszRotate string
		//
		hr = StringCchLength(lpszRotate, 22, &pcch);
		if (FAILED(hr))
		{
		// TODO: write error handler
		} 
		LPSIZE sizeText = new SIZE();
		GetTextExtentPoint32(hdc,lpszRotate,pcch,sizeText);
		TextOut(hdc, rc->left / 2, rc->bottom -((rc->bottom-sizeText->cx)/2), 
			lpszRotate, pcch); 
		SelectObject(hdc, hfntPrev); 
		delete sizeText;
		DeleteObject(hfnt); 
	//} 
	 
	// Reset the background mode to its default. 
	 
	SetBkMode(hdc, OPAQUE); 
	 
	// Free the memory allocated for the LOGFONT structure. 
	 
	LocalFree((LOCALHANDLE) plf); 
} 


//define child windows
#define ID_preview_window 101;
#define ID_title1 102;
#define ID_view_label 103;
#define ID_focus_label 104;
#define ID_view_value 105;
#define ID_focus_value 106;
#define ID_direction_label 107;
#define ID_angle_label 108;
#define ID_direction_value 109;
#define ID_angle_value 110;
#define ID_quality_label 111;
#define ID_quality_value 112;
#define ID_average_label 113;
#define ID_average_value 114;
#define ID_title2 115;
#define ID_vicom_button 116;
#define ID_opt1_button 117;
#define ID_opt2_button 118;
#define ID_opt3_button 119;
#define ID_vicom_status 120;
#define ID_opt1_status 121;
#define ID_opt2_status 122;
#define ID_opt3_status 123;
#define ID_scrollx 124;
#define ID_scrolly 125;
#define ID_scrollz 126;
#define ID_scrollxlabel 127;
#define ID_scrollylabel 128;
#define ID_scrollzlabel 129;
#define ID_scrollzbox 130;
#define ID_displaylabel 131;
#define ID_displaytoggle 132;
#define ID_workinglabel 133;
#define ID_opt4_status 134;
#define ID_opt4_button 135;
#define ID_dropimage 136;
#define ID_compare_button 137;
#define ID_compare_photo 138;
#define ID_compare_value 139;
#define ID_up 140;
#define ID_down 141
#define ID_opt5_status 142;
#define ID_opt5_button 143;

//all the windows and buttons
HWND right_window;
HWND preview_window;
HWND title1;
HWND view_label;
HWND focus_label;
HWND view_value;
HWND focus_value;
HWND direction_label;
HWND angle_label;
HWND direction_value;
HWND angle_value;
HWND quality_label;
HWND quality_value;
HWND average_label;
HWND average_value;
HWND title2;
HWND vicom_button;
HWND opt1_button;
HWND opt2_button;
HWND opt3_button;
HWND vicom_status;
HWND opt1_status;
HWND opt2_status;
HWND opt3_status;
HWND scrollx;
HWND scrolly;
HWND scrollz;
HWND scrollxlabel;
HWND scrollylabel;
HWND scrollzlabel;
HWND scrollzbox;
HWND displaylabel;
HWND displaytoggle;
HWND workinglabel;
HWND opt4_status;
HWND opt4_button;
HWND dropimage;
HWND compare_button;
HWND compare_photo;
HWND compare_value;
HWND up;
HWND down;
HWND opt5_button;
HWND opt5_status;

//strings
char PovRightWinClass[] = CLASSNAMEPREFIX "SplitRightClass" ;
char preview_windowClass [] = CLASSNAMEPREFIX "preview_window";
char title1Class [] = CLASSNAMEPREFIX "title1";
char view_labelClass [] = CLASSNAMEPREFIX "view_label";
char focus_labelClass [] = CLASSNAMEPREFIX "focus_label";
char view_valueClass [] = CLASSNAMEPREFIX "view_value";
char focus_valueClass [] = CLASSNAMEPREFIX "focus_value";
char direction_labelClass [] = CLASSNAMEPREFIX "direction_label";
char angle_labelClass [] = CLASSNAMEPREFIX "angle_label";
char direction_valueClass [] = CLASSNAMEPREFIX "direction_value";
char angle_valueClass [] = CLASSNAMEPREFIX "angle_value";
char quality_labelClass [] = CLASSNAMEPREFIX "quality_label";
char quality_valueClass [] = CLASSNAMEPREFIX "quality_value";
char average_labelClass [] = CLASSNAMEPREFIX "average_label";
char average_valueClass [] = CLASSNAMEPREFIX "average_value";
char title2Class [] = CLASSNAMEPREFIX "title2";
char vicom_buttonClass [] = CLASSNAMEPREFIX "vicom_button";
char opt1_buttonClass [] = CLASSNAMEPREFIX "opt1_button";
char opt2_buttonClass [] = CLASSNAMEPREFIX "opt2_button";
char opt3_buttonClass [] = CLASSNAMEPREFIX "opt3_button";
char vicom_statusClass [] = CLASSNAMEPREFIX "vicom_status";
char opt1_statusClass [] = CLASSNAMEPREFIX "opt1_status";
char opt2_statusClass [] = CLASSNAMEPREFIX "opt2_status";
char opt3_statusClass [] = CLASSNAMEPREFIX "opt3_status";
char scrollxClass [] = CLASSNAMEPREFIX "scrollx";
char scrollyClass [] = CLASSNAMEPREFIX "scrolly";
char scrollzClass [] = CLASSNAMEPREFIX "scrollz";
char scrollxlabelClass [] = CLASSNAMEPREFIX "scrollxlabel";
char scrollylabelClass [] = CLASSNAMEPREFIX "scrollylabel";
char scrollzlabelClass [] = CLASSNAMEPREFIX "scrollzlabel";
char scrollzboxClass [] = CLASSNAMEPREFIX "scrollzbox";
char displaylabelClass [] = CLASSNAMEPREFIX "displaylabelClass";
char displaytoggleClass [] = CLASSNAMEPREFIX "displaytoggleClass";
char workinglabelClass [] = CLASSNAMEPREFIX "workinglabelClass";
char opt4_statusClass [] = CLASSNAMEPREFIX "statusClass";
char opt4_buttonClass [] = CLASSNAMEPREFIX "opt4_buttonClass";
char dropimageClass [] = CLASSNAMEPREFIX "dropimageClass";
char compare_buttonClass [] = CLASSNAMEPREFIX "compare_button";
char compare_photoClass [] = CLASSNAMEPREFIX "compare_photo";
char compare_valueClass [] = CLASSNAMEPREFIX "compare_value";
char upClass [] = CLASSNAMEPREFIX "up";
char downClass [] = CLASSNAMEPREFIX "down";
char opt5_buttonClass [] = CLASSNAMEPREFIX "opt5_button";
char opt5_statusClass [] = CLASSNAMEPREFIX "opt5_status";

struct windowinfo
{
	//initialise values
	windowinfo() : style(0),cbClsExtra(0),cbWndExtra(0),hCursor(LoadCursor (NULL, IDC_ARROW)),
		hbrBackground ((HBRUSH) (COLOR_MENU + 1)),lpszMenuName(NULL), dwExStyle(WS_EX_WINDOWEDGE),
		lpWindowName (""), dwStyle(WS_CHILD), lpParam(NULL){}

	//register info
	UINT style;
    WNDPROC lpfnWndProc;
    int cbClsExtra;
    int cbWndExtra;
    HCURSOR hCursor;
    HBRUSH hbrBackground;
    LPCTSTR lpszMenuName;
    LPCTSTR lpszClassName;
	
	//style info
	DWORD dwExStyle;
    LPCTSTR lpWindowName;
    DWORD dwStyle;
    HMENU hMenu;
    LPVOID lpParam;
};
//put all variables into arrays to work with them
windowinfo info[44];

//the callbacks
void repaintAll()
{
	InvalidateRect (right_window, NULL, FALSE);
}
void repaint(HWND h)
{
	InvalidateRect (h, NULL, TRUE);
}
void repaintImage()
{
	InvalidateRect (preview_window, NULL, FALSE);
}
void resetScroll()
{
	SetScrollRange(scrollx,SB_CTL, -scrollLim, scrollLim,TRUE);
	SetScrollRange(scrolly,SB_CTL, -scrollLim, scrollLim,TRUE);
	SetScrollRange(scrollz,SB_CTL, -scrollLim, scrollLim,TRUE);
}
SCROLLINFO si;
void setScroll(int x, int y, int z)
{
	setScrollX(x);
	setScrollY(y);
	setScrollZ(z);
	repaintAll();
}
void setScrollX(int x)
{
	SetScrollPos(scrollx, SB_CTL, x, FALSE);
}
void setScrollY(int y)
{
	SetScrollPos(scrolly, SB_CTL, -y, FALSE);
}
void setScrollZ(int z)
{
	SetScrollPos(scrollz, SB_CTL, -z, FALSE);
}
int updateScroll(HWND hwnd, int loword)
{
	//the horizontal scroll bar is the X value
	// Get all the horizontal scroll bar information 
	si.cbSize = sizeof (si);
	si.fMask  = SIF_ALL;
	// Save the position for comparison later on
	GetScrollInfo (hwnd, SB_CTL, &si);
	int xPos = si.nPos;
	switch (loword)
	{
		 // user clicked left arrow
		 case SB_LINELEFT: 
			  si.nPos -= 1;
			  break;
              
		 // user clicked right arrow
		 case SB_LINERIGHT: 
			  si.nPos += 1;
			  break;
              
		 // user clicked the scroll bar shaft left of the scroll box
		 case SB_PAGELEFT:
			 si.nPos -= (si.nMax-si.nMin)/10;
			  break;
              
		 // user clicked the scroll bar shaft right of the scroll box
		 case SB_PAGERIGHT:
			  si.nPos += (si.nMax-si.nMin)/10;
			  break;
              
		 // user dragged the scroll box
		 case SB_THUMBTRACK: 
			  si.nPos = si.nTrackPos;
			  break;
              
		 default :
			  break;
	}
	// Set the position and then retrieve it.  Due to adjustments
	//   by Windows it may not be the same as the value set.
	si.fMask = SIF_POS;
	SetScrollInfo (hwnd, SB_CTL, &si, TRUE);
	
	GetScrollInfo (hwnd, SB_CTL, &si);
	return si.nPos;
}
LRESULT CALLBACK PovRightWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		//handle messages from child windows
		case WM_COMMAND:
			{
				switch (wParam)
				{	
					//vicom button
					case 116:
						{
							bool x = getVicon();
							setVicon(!x);
							InvalidateRect (right_window, NULL, FALSE);
							return 0;
						}
					//optimsation 1
					case 117:
						{
							bool x = getOptimsation1();
							setOptimsation1(!x);
							InvalidateRect (right_window, NULL, FALSE);
							return 0;
						}
					//optimsation 2
					case 118:
						{
							bool x = getOptimsation2();
							setOptimsation2(!x);
							InvalidateRect (right_window, NULL, FALSE);
							return 0;
						}
					//optimsation 3
					case 119:
						{
							bool x = getOptimsation3();
							setOptimsation3(!x);
							InvalidateRect (opt3_status, NULL, FALSE);
							return 0;
						}
					//optimsation 4
					case 135:
						{
							bool x = getOptimsation4();
							setOptimsation4(!x);
							InvalidateRect (right_window, NULL, FALSE);
							return 0;
						}
					//screen
					case 132:
						{
							toggleScreen();
							InvalidateRect (right_window, NULL, FALSE);
							return 0;
						}
					//drop image
					case 136:
						{
							dropScreen();
							InvalidateRect (right_window, NULL, FALSE);
							return 0;
						}
					//compare_button
					case 137:
						{
							setCompare(!getCompare());
							InvalidateRect (compare_value, NULL, FALSE);
							return 0;
						}
					//compare_photo
					case 138:
						{
							grabImage();
							InvalidateRect (compare_value, NULL, FALSE);
							return 0;
						}
					//up
					case 140:
						{
							setToleranceValUp();
							InvalidateRect (opt3_status, NULL, FALSE);
							return 0;
						}
					//down
					case 141:
						{
							setToleranceValDown();
							InvalidateRect (opt3_status, NULL, FALSE);
							return 0;
						}
					//opt 5
					case 142:
						{
							bool x = getOptimsation5();
							setOptimsation5(!x);
							InvalidateRect (right_window, NULL, FALSE);
							return 0;
						}
				}
			}
		case WM_SIZE : 
			{
				//get dimensions of box
				RECT rcClient; 
				GetClientRect(right_window, &rcClient);
				int width = rcClient.right - rcClient.left;
				int height = rcClient.bottom - rcClient.top;

				int bgap = 20;
				int sgap = 6;
				int previewheight = 150;
				int previewwidth = width-2*bgap;
				int titlewidth = 340;
				int titleheight = 25;
				int boxwidth = (previewwidth-3*sgap)/4;
				int boxheight = 18;
				int bottonwidth = (previewwidth-bgap)/2;
				int buttonheight = titleheight;
				int scrollwidth = 20;

				int total = bgap;
				int offset = (width-previewwidth)/2;

				//calculate the dimensions of view area
				int alltotal = bgap + 13*sgap + 5*boxheight + 6*buttonheight + 2*titleheight + scrollwidth;
				int rem = height - alltotal;
				if (rem > previewheight){
					previewheight = rem;
					previewwidth = (previewheight/3)*4;
					//but width may be too big
					if (previewwidth > (width-4*sgap-2*scrollwidth-2*boxheight))
					{
						previewwidth = width-4*sgap-2*scrollwidth-2*boxheight;
						previewheight = (previewwidth/4)*3;
					}
				}
				else
				{
					previewwidth = (previewheight/3)*4;
				}			
				
				MoveWindow(displaylabel, (width-previewwidth)/2, total-bgap, previewwidth, bgap, TRUE); 
				ShowWindow(displaylabel, SW_SHOW);
				MoveWindow(preview_window, (width-previewwidth)/2, total, previewwidth, previewheight, TRUE); 
				ShowWindow(preview_window, SW_SHOW);
				MoveWindow(scrolly, (width-previewwidth)/2-sgap-scrollwidth, total, scrollwidth, previewheight, TRUE); 
				ShowWindow(scrolly, SW_SHOW);
				MoveWindow(scrollylabel, (width-previewwidth)/2-sgap-scrollwidth-boxheight, total, boxheight, previewheight, TRUE); 
				ShowWindow(scrollylabel, SW_SHOW);
				
				MoveWindow(scrollzbox, (width-previewwidth)/2+sgap+previewwidth, total, scrollwidth, previewheight, TRUE); 
				ShowWindow(scrollzbox, SW_SHOW);
				MoveWindow(scrollz, 0, 0, scrollwidth, previewheight, TRUE); 
				ShowWindow(scrollz, SW_SHOW);
				MoveWindow(scrollzlabel, (width-previewwidth)/2+sgap+previewwidth+scrollwidth, total, boxheight, previewheight, TRUE); 
				ShowWindow(scrollzlabel, SW_SHOW);

				total = total + sgap + previewheight;
				MoveWindow(scrollx, (width-previewwidth)/2, total, previewwidth, scrollwidth, TRUE); 
				ShowWindow(scrollx, SW_SHOW);
				total = total + scrollwidth;
				MoveWindow(scrollxlabel, (width-previewwidth)/2+boxwidth, total, previewwidth-2*boxwidth, boxheight, TRUE); 
				ShowWindow(scrollxlabel, SW_SHOW);
				MoveWindow(displaytoggle, (width-previewwidth)/2+previewwidth-boxwidth, total, boxwidth, buttonheight, TRUE); 
				ShowWindow(displaytoggle, SW_SHOW);
				//MoveWindow(dropimage, ((width-previewwidth)/2), total, boxwidth, buttonheight, TRUE); 
				//ShowWindow(dropimage, SW_SHOW);

				total = total + sgap + boxheight;
				MoveWindow(title1, (width-titlewidth)/2, total, titlewidth, titleheight, TRUE); 
				ShowWindow(title1, SW_SHOW);
				total = total + sgap + titleheight;
				MoveWindow(view_label, offset, total, boxwidth, boxheight, TRUE); 
				ShowWindow(view_label, SW_SHOW);
				MoveWindow(view_value, offset+sgap+boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(view_value, SW_SHOW);
				MoveWindow(quality_label, offset+2*sgap+2*boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(quality_label, SW_SHOW);
				MoveWindow(quality_value, offset+3*sgap+3*boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(quality_value, SW_SHOW);
				total = total + sgap + boxheight;
				MoveWindow(direction_label, offset, total, boxwidth, boxheight, TRUE); 
				ShowWindow(direction_label, SW_SHOW);
				MoveWindow(direction_value, offset+sgap+boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(direction_value, SW_SHOW);
				MoveWindow(angle_label, offset+2*sgap+2*boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(angle_label, SW_SHOW);
				MoveWindow(angle_value, offset+3*sgap+3*boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(angle_value, SW_SHOW);
				total = total + sgap + boxheight;
				MoveWindow(focus_label, offset, total, boxwidth, boxheight, TRUE); 
				ShowWindow(focus_label, SW_SHOW);
				MoveWindow(focus_value, offset+sgap+boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(focus_value, SW_SHOW);
				MoveWindow(average_label, offset+2*sgap+2*boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(average_label, SW_SHOW);
				MoveWindow(average_value, offset+3*sgap+3*boxwidth, total, boxwidth, boxheight, TRUE); 
				ShowWindow(average_value, SW_SHOW);
				total = total + sgap + buttonheight;
				int indent = (width - buttonheight*2 - bottonwidth - 2* sgap)/2;
				MoveWindow(compare_button, indent, total, bottonwidth/2, buttonheight, TRUE); 
				ShowWindow(compare_button, SW_SHOW);
				MoveWindow(compare_value, indent+sgap+bottonwidth/2, total, buttonheight*2, buttonheight, TRUE); 
				ShowWindow(compare_value, SW_SHOW);
				MoveWindow(compare_photo, indent+2*sgap+bottonwidth/2+buttonheight*2, total, bottonwidth/2, buttonheight, TRUE); 
				ShowWindow(compare_photo, SW_SHOW);
				total = total + sgap + boxheight;
				MoveWindow(title2, (width-titlewidth)/2, total,  titlewidth, titleheight, TRUE);
				ShowWindow(title2, SW_SHOW);
				//MoveWindow(workinglabel, offset, total, bottonwidth-sgap-2*buttonheight, titleheight, TRUE); 
				//ShowWindow(workinglabel, SW_SHOW);
				total = total + sgap + titleheight;
				MoveWindow(vicom_button, offset, total, bottonwidth-sgap-2*buttonheight, 2*buttonheight+sgap, TRUE); 
				ShowWindow(vicom_button, SW_SHOW);
				MoveWindow(vicom_status, offset+bottonwidth-2*buttonheight, total, 2*buttonheight+sgap, 2*buttonheight+sgap, TRUE); 
				ShowWindow(vicom_status, SW_SHOW);
				MoveWindow(opt1_button, offset+bottonwidth+bgap, total, bottonwidth-sgap-buttonheight, buttonheight, TRUE); 
				ShowWindow(opt1_button, SW_SHOW);
				MoveWindow(opt1_status, offset+2*bottonwidth+bgap-buttonheight, total, buttonheight, buttonheight, TRUE); 
				ShowWindow(opt1_status, SW_SHOW);
				total = total + sgap + buttonheight;
				MoveWindow(opt2_button, offset+bottonwidth+bgap, total, bottonwidth-sgap-buttonheight, buttonheight, TRUE); 
				ShowWindow(opt2_button, SW_SHOW);
				MoveWindow(opt2_status, offset+2*bottonwidth+bgap-buttonheight, total, buttonheight, buttonheight, TRUE); 
				ShowWindow(opt2_status, SW_SHOW);
				total = total + sgap + buttonheight;
				MoveWindow(opt3_button, offset+bottonwidth+bgap, total, bottonwidth-sgap-buttonheight-2*buttonheight, buttonheight, TRUE); 
				ShowWindow(opt3_button, SW_SHOW);
				MoveWindow(up, offset+bottonwidth+bottonwidth-sgap-buttonheight+bgap-2*buttonheight, total, buttonheight, buttonheight, TRUE); 
				ShowWindow(up, SW_SHOW);
				MoveWindow(down, offset+bottonwidth+bgap+bottonwidth-sgap-buttonheight-1*buttonheight, total, buttonheight, buttonheight, TRUE); 
				ShowWindow(down, SW_SHOW);
				MoveWindow(opt3_status, offset+2*bottonwidth+bgap-buttonheight, total, buttonheight, buttonheight, TRUE); 
				ShowWindow(opt3_status, SW_SHOW);
				total = total + sgap + buttonheight;
				MoveWindow(opt4_button, offset+bottonwidth+bgap, total, bottonwidth-sgap-buttonheight, buttonheight, TRUE); 
				ShowWindow(opt4_button, SW_SHOW);
				MoveWindow(opt4_status, offset+2*bottonwidth+bgap-buttonheight, total, buttonheight, buttonheight, TRUE); 
				ShowWindow(opt4_status, SW_SHOW);
				total = total + sgap + buttonheight;
				MoveWindow(opt5_button, offset+bottonwidth+bgap, total, bottonwidth-sgap-buttonheight, buttonheight, TRUE); 
				ShowWindow(opt5_button, SW_SHOW);
				MoveWindow(opt5_status, offset+2*bottonwidth+bgap-buttonheight, total, buttonheight, buttonheight, TRUE); 
				ShowWindow(opt5_status, SW_SHOW);
				repaintAll();
				return 0;
			}
		case WM_HSCROLL:
			{
				//update the x value
				int pos = updateScroll(scrollx,LOWORD (wParam));
				newViewX(pos,scrollLim);
				return 0;
			}
		case WM_VSCROLL:
			{
				//the y slider
				int pos = updateScroll(scrolly,LOWORD (wParam));
				newViewY(-pos,scrollLim);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK preview_window_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  int                   dest_width ;
  int                   dest_height ;
  int                   dest_xoffset ;
  int                   dest_yoffset ;
  int                   oldMode ;
  HDC                   hdc ;
  HDC                   hdcMemory ;
  RECT                  rect ;
  HPEN                  hpen ;
  char                  str [512] ;
  char                  *s ;
  bool                  zoomed = IsZoomed (hwnd) != 0 ;
  POINT                 pt ;
  POINT                 pts [5] ;
  double                aspect_ratio ;
  double                screen_aspect ;
  HBITMAP               oldBmp ;
  MINMAXINFO            *pInfo ;
  PAINTSTRUCT           ps ;
  static HBITMAP        errorBitmap = NULL ;
  static int            RBand = 0 ;
  static POINT          RB1 ;
  static POINT          RB2 ;
  static int            lastX = -1 ;
  static int            lastY = -1 ;

  switch (message)
  {
    case WM_PAINT :

		 GetClientRect (hwnd, &rect) ;
         if (zoomed)
         {
           aspect_ratio = (double) render_width / render_height ;
           screen_aspect = (double) rect.right / rect.bottom ;
           if (aspect_ratio >= screen_aspect)
           {
             dest_width = rect.right ;
             dest_height = (int) ((double) rect.right / aspect_ratio) ;
           }
           else
           {
             dest_width = (int) ((double) rect.bottom * aspect_ratio) ;
             dest_height = rect.bottom ;
           }
           dest_xoffset = (rect.right - dest_width) / 2 ;
           dest_yoffset = (rect.bottom - dest_height) / 2 ;
         }
         else
         {
           dest_xoffset = dest_yoffset = 0 ;
           dest_width = rect.right ;
           dest_height = rect.bottom ;
         }

         hdc = BeginPaint (hwnd, &ps) ;
         oldMode = SetStretchBltMode (hdc, STRETCH_DELETESCANS) ;
         if (hPalApp)
         {
           SelectPalette (hdc, hPalApp, false) ;
           RealizePalette (hdc) ;
         }
           dest_xoffset = 0;//-renderwin_xoffset ;
           dest_yoffset = 0;//-renderwin_yoffset ;
           dest_width = render_width ;
           dest_height = render_height ;
           GetClientRect (hwnd, &rect) ;
           if (rect.right > dest_width)
             BitBlt (hdc, dest_width, 0, rect.right - dest_width, rect.bottom, NULL, 0, 0, BLACKNESS) ;
           if (rect.bottom > dest_height)
             BitBlt (hdc, 0, dest_height, rect.right, rect.bottom - dest_height, NULL, 0, 0, BLACKNESS) ;
		   int testvar;
		   if (getScreen())
			{
				testvar = StretchDIBits (hdc,
                            dest_xoffset,
                            dest_yoffset,
							rect.right,
							rect.bottom,
                            0,
                            0,
                            render_bitmap.header.biWidth,
                            render_bitmap.header.biHeight,
                            render_bitmap_surface,
                            (LPBITMAPINFO) &render_bitmap,
                            DIB_RGB_COLORS,
                            SRCCOPY);
			}
			else
			{
				testvar = StretchDIBits (hdc,
                            dest_xoffset,
                            dest_yoffset,
							rect.right,
							rect.bottom,
                            0,
                            0,
                            render_bitmap.header.biWidth,
                            render_bitmap.header.biHeight,
                            render_priority_surface,
                            (LPBITMAPINFO) &render_bitmap,
                            DIB_RGB_COLORS,
                            SRCCOPY);
			}
         if (testvar<=0)
         {
           // hmmmm ... it seems we've run into a Windows bug of some form. When rendering a
           // large scene file (it used some 200mb of swap plus 80+mb of real memory on a 128mb
           // box) at a resolution of 1280x1024 (same as screen resolution) on Windows NT 4.0,
           // StretchDIBits () was observed to return zero (which is not failure, but not success
           // either :).

           GetClientRect (preview_window, &rect) ;
           BitBlt (hdc, 0, 0, dest_width, dest_height, NULL, 0, 0, WHITENESS) ;
           if (errorBitmap == NULL)
             errorBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE (BMP_STRETCHDIBITS)) ;
           hdcMemory = CreateCompatibleDC (hdc) ;
           oldBmp = (HBITMAP)SelectObject (hdcMemory, errorBitmap) ;
           BitBlt (hdc, rect.right / 2 - 157, rect.bottom / 2 - 10, 345, 21, hdcMemory, 0, 0, SRCCOPY) ;
           SelectObject (hdcMemory, oldBmp) ;
           DeleteDC (hdcMemory) ;
         }
         SetStretchBltMode (hdc, oldMode) ;
         EndPaint (hwnd, &ps) ;
         return (0) ;
  }
  return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK title1_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(title1, &ps);
				GetClientRect(title1, &rcClient);
				char title[] = "Message Details";
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				EndPaint(title1, &ps);
				return 0;
			}
		case WM_COMMAND:
			{
			
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK view_label_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(view_label, &ps);
				GetClientRect(view_label, &rcClient);

				char title []= "Viewpoint";
				DrawMessage(hdc, &rcClient, title_Font ,title,RIGHT);

				EndPaint(view_label, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK focus_label_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(focus_label, &ps);
				GetClientRect(focus_label, &rcClient);

				char title []= "Camera Focus";
				DrawMessage(hdc, &rcClient, title_Font ,title,RIGHT);

				EndPaint(focus_label, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK view_value_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(view_value, &ps);
				GetClientRect(view_value, &rcClient);

				if (getViewRefresh())
				{
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}
				else
				{
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}

				Coordinate c = getDrawViewpoint();
				char title [100];
				sprintf(title, "(%.2g,%.2g,%.2g)", c.x,c.y,c.z);
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);

				EndPaint(view_value, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK focus_value_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(focus_value, &ps);
				GetClientRect(focus_value, &rcClient);

				if (getViewRefresh())
				{
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}
				else
				{
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}

				Coordinate c = getFocus();
				char title [100];
				sprintf(title, "(%.2g,%.2g,%.2g)", c.x,c.y,c.z);
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);

				EndPaint(focus_value, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK direction_label_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(direction_label, &ps);
				GetClientRect(direction_label, &rcClient);

				char title []= "Direction";
				DrawMessage(hdc, &rcClient, title_Font ,title,RIGHT);

				EndPaint(direction_label, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK angle_label_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(angle_label, &ps);
				GetClientRect(angle_label, &rcClient);

				char title []= "Angle";
				DrawMessage(hdc, &rcClient, title_Font ,title,RIGHT);

				EndPaint(angle_label, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK direction_value_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(direction_value, &ps);
				GetClientRect(direction_value, &rcClient);

				if (getViewRefresh())
				{
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}
				else
				{
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}

				Coordinate c = getDirection();
				char title [100];
				sprintf(title, "(%.2g,%.2g,%.2g)", c.x,c.y,c.z);
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);

				EndPaint(direction_value, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK angle_value_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(angle_value, &ps);
				GetClientRect(angle_value, &rcClient);

				if (getViewRefresh())
				{
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}
				else
				{
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}

				char title [10];
				double x = getAngle();
				sprintf(title, "%.3g%c", x, 0x00B0);
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);

				EndPaint(angle_value, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK quality_label_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(quality_label, &ps);
				GetClientRect(quality_label, &rcClient);

				char title [] = "Current Area";
				DrawMessage(hdc, &rcClient, title_Font ,title,RIGHT);

				EndPaint(quality_label, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK quality_value_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(quality_value, &ps);
				GetClientRect(quality_value, &rcClient);

				int c = getArea();
				char title [100];
				wsprintf(title, "%d", c);
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);

				EndPaint(quality_value, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK average_label_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_LBUTTONDOWN:
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(average_label, &ps);
				GetClientRect(average_label, &rcClient);

				char title [] = "Render Speed";
				DrawMessage(hdc, &rcClient, title_Font ,title,RIGHT);

				EndPaint(average_label, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK average_value_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
		{
			case WM_PAINT:
				{
					//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(average_value, &ps);
				GetClientRect(average_value, &rcClient);

				char title [100];
				long speed = getAvgTime();
				wsprintf(title, "%li pix/sec", speed);
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);

				EndPaint(average_value, &ps);
				return 0;
					return 0;
				}
			case WM_CREATE:
				{
					return 0;
				}
			case WM_LBUTTONDOWN:
				{
					return 0;
				}
		}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK title2_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_CREATE:
			{
				return 0;
			}
		case WM_SIZE : 
			{
				return 0;
			}
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(title2, &ps);
				GetClientRect(title2, &rcClient);
				char title[] = "Optimisations";
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				EndPaint(title2, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK vicom_button_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
};
LRESULT CALLBACK opt1_button_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
};
LRESULT CALLBACK opt2_button_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
};
LRESULT CALLBACK opt3_button_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
};
LRESULT CALLBACK vicom_status_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(vicom_status, &ps);
				GetClientRect(vicom_status, &rcClient);
				
				if (getVicon()){
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title []= "On";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}
				else {
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title [] = "Off";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}

				EndPaint(vicom_status, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK opt1_status_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(opt1_status, &ps);
				GetClientRect(opt1_status, &rcClient);

				if (getOptimsation1()){
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title []= "On";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}
				else {
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title [] = "Off";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}

				EndPaint(opt1_status, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK opt2_status_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(opt2_status, &ps);
				GetClientRect(opt2_status, &rcClient);
				
				if (getOptimsation2()){
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title []= "On";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}
				else {
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title [] = "Off";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}

				EndPaint(opt2_status, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK opt3_status_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(opt3_status, &ps);
				GetClientRect(opt3_status, &rcClient);
				
				char title [100];
				int val = getTolerance();
				wsprintf(title, "%i", val);

				if (getOptimsation3()){
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}
				else {
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}

				EndPaint(opt3_status, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK scrollx_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK scrolly_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK scrollzbox_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
			case WM_VSCROLL:
			{
				//the y slider
				int pos = updateScroll(scrollz,LOWORD (wParam));
				newViewZ(-pos,scrollLim);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK scrollz_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK scrollxlabel_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(scrollxlabel, &ps);
				GetClientRect(scrollxlabel, &rcClient);

				char title []= "left/right";
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);

				EndPaint(scrollxlabel, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK scrollylabel_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(scrollylabel, &ps);
				GetClientRect(scrollylabel, &rcClient);

				LPSTR title = "up/down";
				DrawRotateMessage(hdc, &rcClient, title_Font ,title,90);

				EndPaint(scrollylabel, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK scrollzlabel_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(scrollzlabel, &ps);
				GetClientRect(scrollzlabel, &rcClient);

				LPSTR myString = "forewards/backwards";
				DrawRotateMessage(hdc, &rcClient, title_Font ,myString,90);

				EndPaint(scrollzlabel, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK displaylabel_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
			case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(displaylabel, &ps);
				GetClientRect(displaylabel, &rcClient);

				if (getScreen())
				{
					char title []= "Picture view";
					DrawMessage(hdc, &rcClient, title_Font ,title,LEFT);
				}
				else
				{
					char title []= "Priority view";
					DrawMessage(hdc, &rcClient, title_Font ,title,LEFT);
				}

				EndPaint(displaylabel, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK displaytoggle_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK workinglabel_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(workinglabel, &ps);
				GetClientRect(workinglabel, &rcClient);

				if (!getWorking())
				{
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title []= "Tracing";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}
				else 
				{
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title [] = "Working";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}

				EndPaint(workinglabel, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK opt4_status_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(opt4_status, &ps);
				GetClientRect(opt4_status, &rcClient);
				
				if (getOptimsation4()){
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title []= "On";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}
				else {
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title [] = "Off";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}

				EndPaint(opt4_status, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK opt4_button_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK dropimage_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK compare_button_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK compare_photo_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK compare_value_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(compare_value, &ps);
				GetClientRect(compare_value, &rcClient);

				if (getCompare())
				{
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}
				else
				{
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
				}

				char title [100];
				sprintf(title, "%d%%", getCompareValue());
				DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);

				EndPaint(compare_value, &ps);
				return 0;
			}
	}
    return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK up_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK down_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
LRESULT CALLBACK opt5_button_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
};
LRESULT CALLBACK opt5_status_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_PAINT:
			{
				//paint the text in the box
				RECT rcClient;
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(opt5_status, &ps);
				GetClientRect(opt5_status, &rcClient);
				
				char title [100];
				int val = getTolerance();
				wsprintf(title, "%i", val);

				if (getOptimsation5()){
					SelectObject(hdc, greenBrush);
					SelectObject(hdc, greenpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title []= "On";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}
				else {
					SelectObject(hdc, redBrush);
					SelectObject(hdc, redpen);
					Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					char title [] = "Off";
					DrawMessage(hdc, &rcClient, title_Font ,title,CENTER);
				}

				EndPaint(opt5_status, &ps);
				return 0;
			}
	}
	return (DefWindowProc (hwnd, message, wParam, lParam)) ;
}
int registercontrol(HINSTANCE hInstance, HICON ourIcon)
{
	//callback pointer
	info[0].lpfnWndProc = PovRightWndProc;
	info[1].lpfnWndProc = preview_window_callback;
	info[2].lpfnWndProc = title1_callback;
	info[3].lpfnWndProc = view_label_callback;
	info[4].lpfnWndProc = focus_label_callback;
	info[5].lpfnWndProc = view_value_callback;
	info[6].lpfnWndProc = focus_value_callback;
	info[7].lpfnWndProc = direction_label_callback;
	info[8].lpfnWndProc = angle_label_callback;
	info[9].lpfnWndProc = direction_value_callback;
	info[10].lpfnWndProc = angle_value_callback;
	info[11].lpfnWndProc = quality_label_callback;
	info[12].lpfnWndProc = quality_value_callback;
	info[13].lpfnWndProc = average_label_callback;
	info[14].lpfnWndProc = average_value_callback;
	info[15].lpfnWndProc = title2_callback;
	info[16].lpfnWndProc = vicom_button_callback;
	info[17].lpfnWndProc = opt1_button_callback;
	info[18].lpfnWndProc = opt2_button_callback;
	info[19].lpfnWndProc = opt3_button_callback;
	info[20].lpfnWndProc = vicom_status_callback;
	info[21].lpfnWndProc = opt1_status_callback;
	info[22].lpfnWndProc = opt2_status_callback;
	info[23].lpfnWndProc = opt3_status_callback;
	info[24].lpfnWndProc = scrollx_callback;
	info[25].lpfnWndProc = scrolly_callback;
	info[26].lpfnWndProc = scrollz_callback;
	info[27].lpfnWndProc = scrollxlabel_callback;
	info[28].lpfnWndProc = scrollylabel_callback;
	info[29].lpfnWndProc = scrollzlabel_callback;
	info[30].lpfnWndProc = scrollzbox_callback;
	info[31].lpfnWndProc = displaylabel_callback;
	info[32].lpfnWndProc = displaytoggle_callback;
	info[33].lpfnWndProc = workinglabel_callback;
	info[34].lpfnWndProc = opt4_status_callback;
	info[35].lpfnWndProc = opt4_button_callback;
	info[36].lpfnWndProc = dropimage_callback;
	info[37].lpfnWndProc = compare_button_callback;
	info[38].lpfnWndProc = compare_photo_callback;
	info[39].lpfnWndProc = compare_value_callback;
	info[40].lpfnWndProc = up_callback;
	info[41].lpfnWndProc = down_callback;
	info[42].lpfnWndProc = opt5_button_callback;
	info[43].lpfnWndProc = opt5_status_callback;

	//name of window
	info[0].lpszClassName = PovRightWinClass;
	info[1].lpszClassName = preview_windowClass;
	info[2].lpszClassName = title1Class;
	info[3].lpszClassName = view_labelClass;
	info[4].lpszClassName = focus_labelClass;
	info[5].lpszClassName = view_valueClass;
	info[6].lpszClassName = focus_valueClass;
	info[7].lpszClassName = direction_labelClass;
	info[8].lpszClassName = angle_labelClass;
	info[9].lpszClassName = direction_valueClass;
	info[10].lpszClassName = angle_valueClass;
	info[11].lpszClassName = quality_labelClass;
	info[12].lpszClassName = quality_valueClass;
	info[13].lpszClassName = average_labelClass;
	info[14].lpszClassName = average_valueClass;
	info[15].lpszClassName = title2Class;
	info[16].lpszClassName = vicom_buttonClass;
	info[17].lpszClassName = opt1_buttonClass;
	info[18].lpszClassName = opt2_buttonClass;
	info[19].lpszClassName = opt3_buttonClass;
	info[20].lpszClassName = vicom_statusClass;
	info[21].lpszClassName = opt1_statusClass;
	info[22].lpszClassName = opt2_statusClass;
	info[23].lpszClassName = opt3_statusClass;
	info[24].lpszClassName = scrollxClass;
	info[25].lpszClassName = scrollyClass;
	info[26].lpszClassName = scrollzClass;
	info[27].lpszClassName = scrollxlabelClass;
	info[28].lpszClassName = scrollylabelClass;
	info[29].lpszClassName = scrollzlabelClass;
	info[30].lpszClassName = scrollzboxClass;
	info[31].lpszClassName = displaylabelClass;
	info[32].lpszClassName = displaytoggleClass;
	info[33].lpszClassName = workinglabelClass;
	info[34].lpszClassName = opt4_statusClass;
	info[35].lpszClassName = opt4_buttonClass;
	info[36].lpszClassName = dropimageClass;
	info[37].lpszClassName = compare_buttonClass;
	info[38].lpszClassName = compare_photoClass;
	info[39].lpszClassName = compare_valueClass;
	info[40].lpszClassName = upClass;
	info[41].lpszClassName = downClass;
	info[42].lpszClassName = opt5_buttonClass;
	info[43].lpszClassName = opt5_statusClass;
	//window style
	info[1].dwExStyle = WS_EX_WINDOWEDGE;
	info[1].dwStyle = WS_CHILD  | WS_VISIBLE | WS_CLIPSIBLINGS | ES_MULTILINE | WS_BORDER;
	info[1].hbrBackground = (HBRUSH) COLOR_GRAYTEXT;
	info[5].dwStyle = WS_CHILD|WS_BORDER ;
	info[5].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[6].dwStyle = WS_CHILD|WS_BORDER ;
	info[6].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[9].dwStyle = WS_CHILD|WS_BORDER ;
	info[9].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[10].dwStyle = WS_CHILD|WS_BORDER ;
	info[10].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[12].dwStyle = WS_CHILD|WS_BORDER ;
	info[12].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[14].dwStyle = WS_CHILD|WS_BORDER ;
	info[14].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[16].lpWindowName = "Vicom On/Off";
	info[16].dwStyle = WS_CHILD | BS_DEFPUSHBUTTON;
	info[17].lpWindowName = "Non-Tree On/Off";
	info[18].lpWindowName = "Randomization On/Off";
	info[19].lpWindowName = "Edge Detection On/Off";
	info[20].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[20].dwStyle = WS_CHILD|WS_BORDER;
	info[21].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[21].dwStyle = WS_CHILD|WS_BORDER;
	info[22].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[22].dwStyle = WS_CHILD|WS_BORDER;
	info[23].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[23].dwStyle = WS_CHILD|WS_BORDER;
	info[32].lpWindowName = "Toggle Screen";
	info[36].lpWindowName = "Drop Image";
	info[35].lpWindowName = "Linear Interpolation On/Off";
	info[34].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[34].dwStyle = WS_CHILD|WS_BORDER;
	info[37].lpWindowName = "Compare Image";
	info[38].lpWindowName = "Grab Image";
	info[39].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[39].dwStyle = WS_CHILD|WS_BORDER;
	info[40].lpWindowName = "+";
	info[41].lpWindowName = "-";
	info[42].lpWindowName = "Plane Projection On/Off";
	info[43].hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	info[43].dwStyle = WS_CHILD|WS_BORDER;

	//identifiers
	for (int i=1; i<44; i++)
	{
		int x = (int)ID_preview_window;
		x = x+i-1;
		info[i].hMenu = (HMENU) x;
	}

	WNDCLASS    wc ;

	for (int i=0; i<44; i++)
	{
		wc.style         = info[0].style;
		wc.lpfnWndProc   = info[i].lpfnWndProc;
		wc.cbClsExtra    = info[i].cbClsExtra;
		wc.cbWndExtra    = info[i].cbWndExtra;
		wc.hInstance     = hInstance ;
		wc.hIcon         = ourIcon ;
		wc.hCursor       = info[i].hCursor;
		wc.hbrBackground = info[i].hbrBackground;
		wc.lpszMenuName  = info[i].lpszMenuName;
		wc.lpszClassName = info[i].lpszClassName;
		if (RegisterClass (&wc) == false)
		return (false) ;
	}

	return true;
}
bool createItems(HINSTANCE globalinst)
{
	preview_window = CreateWindowEx(info[1].dwExStyle, 
				   info[1].lpszClassName, 
				   info[1].lpWindowName, 
				   info[1].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[1].hMenu,
				   globalinst, 
				   info[1].lpParam);
	if (preview_window == NULL){
		MessageBox (NULL, "ERROR : Could not create window 1.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	title1 = CreateWindowEx(info[2].dwExStyle, 
				   info[2].lpszClassName, 
				   info[2].lpWindowName, 
				   info[2].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[2].hMenu,
				   globalinst, 
				   info[2].lpParam); 
	if (title1 == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	view_label = CreateWindowEx(info[3].dwExStyle, 
				   info[3].lpszClassName, 
				   info[3].lpWindowName, 
				   info[3].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[3].hMenu,
				   globalinst, 
				   info[3].lpParam); 
	if (view_label == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	focus_label = CreateWindowEx(info[4].dwExStyle, 
				   info[4].lpszClassName, 
				   info[4].lpWindowName, 
				   info[4].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[4].hMenu,
				   globalinst, 
				   info[4].lpParam); 
	if (focus_label == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	view_value = CreateWindowEx(info[5].dwExStyle, 
				   info[5].lpszClassName, 
				   info[5].lpWindowName, 
				   info[5].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[5].hMenu,
				   globalinst, 
				   info[5].lpParam); 
	if (view_value == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	focus_value = CreateWindowEx(info[6].dwExStyle, 
				   info[6].lpszClassName, 
				   info[6].lpWindowName, 
				   info[6].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[6].hMenu,
				   globalinst, 
				   info[6].lpParam); 
	if (focus_value == NULL){
		MessageBox (NULL, "ERROR : Could not create window 6.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	direction_label = CreateWindowEx(info[7].dwExStyle, 
				   info[7].lpszClassName, 
				   info[7].lpWindowName, 
				   info[7].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[7].hMenu,
				   globalinst, 
				   info[7].lpParam); 
	if (direction_label == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	angle_label = CreateWindowEx(info[8].dwExStyle, 
				   info[8].lpszClassName, 
				   info[8].lpWindowName, 
				   info[8].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[8].hMenu,
				   globalinst, 
				   info[8].lpParam); 
	if (angle_label == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	direction_value = CreateWindowEx(info[9].dwExStyle, 
				   info[9].lpszClassName, 
				   info[9].lpWindowName, 
				   info[9].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[9].hMenu,
				   globalinst, 
				   info[9].lpParam); 
	if (direction_value == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	angle_value = CreateWindowEx(info[10].dwExStyle, 
				   info[10].lpszClassName, 
				   info[10].lpWindowName, 
				   info[10].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[10].hMenu,
				   globalinst, 
				   info[10].lpParam); 
	if (angle_value == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	quality_label = CreateWindowEx(info[11].dwExStyle, 
				   info[11].lpszClassName, 
				   info[11].lpWindowName, 
				   info[11].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[11].hMenu,
				   globalinst, 
				   info[11].lpParam); 
	if (quality_label == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	quality_value = CreateWindowEx(info[12].dwExStyle, 
				   info[12].lpszClassName, 
				   info[12].lpWindowName, 
				   info[12].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[12].hMenu,
				   globalinst, 
				   info[12].lpParam); 
	if (quality_value == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	average_label = CreateWindowEx(info[13].dwExStyle, 
				   info[13].lpszClassName, 
				   info[13].lpWindowName, 
				   info[13].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[13].hMenu,
				   globalinst, 
				   info[13].lpParam); 
	if (average_label == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	average_value = CreateWindowEx(info[14].dwExStyle, 
				   info[14].lpszClassName, 
				   info[14].lpWindowName, 
				   info[14].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[14].hMenu,
				   globalinst, 
				   info[14].lpParam); 
	if (average_value == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	title2 = CreateWindowEx(info[15].dwExStyle, 
				   info[15].lpszClassName, 
				   info[15].lpWindowName, 
				   info[15].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[15].hMenu,
				   globalinst, 
				   info[15].lpParam); 
	if (title2 == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	vicom_button = CreateWindowEx(info[16].dwExStyle, 
				   "BUTTON", 
				   info[16].lpWindowName, 
				   info[16].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[16].hMenu,
				   globalinst, 
				   info[16].lpParam); 
	if (vicom_button == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt1_button = CreateWindowEx(info[17].dwExStyle, 
				   "BUTTON", 
				   info[17].lpWindowName, 
				   info[17].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[17].hMenu,
				   globalinst, 
				   info[17].lpParam); 
	if (opt1_button == NULL){
		MessageBox (NULL, "ERROR : Could not create window.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt2_button = CreateWindowEx(info[18].dwExStyle, 
				   "BUTTON", 
				   info[18].lpWindowName, 
				   info[18].dwStyle, 
				   0,0,0,0,
				   right_window, 
				   info[18].hMenu,
				   globalinst, 
				   info[18].lpParam); 
	if (opt2_button == NULL){
		MessageBox (NULL, "ERROR : Could not create window 22.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt3_button = CreateWindowEx(info[19].dwExStyle, 
				   "BUTTON", 
				   info[19].lpWindowName, 
				   info[19].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[19].hMenu,
				   globalinst, 
				   info[19].lpParam); 
	if (opt3_button == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	vicom_status = CreateWindowEx(info[20].dwExStyle, 
				   info[20].lpszClassName, 
				   info[20].lpWindowName, 
				   info[20].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);	
	if (vicom_status == NULL){
		MessageBox (NULL, "ERROR : Could not create window 24.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt1_status = CreateWindowEx(info[21].dwExStyle, 
				   info[21].lpszClassName, 
				   info[21].lpWindowName, 
				   info[21].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL); 
	if (opt1_status == NULL){
		MessageBox (NULL, "ERROR : Could not create window 25.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt2_status = CreateWindowEx(info[22].dwExStyle, 
				   info[22].lpszClassName, 
				   info[22].lpWindowName, 
				   info[22].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (opt2_status == NULL){
		MessageBox (NULL, "ERROR : Could not create window 26.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt3_status = CreateWindowEx(info[23].dwExStyle, 
				   info[23].lpszClassName, 
				   info[23].lpWindowName, 
				   info[23].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (opt3_status == NULL){
		MessageBox (NULL, "ERROR : Could not create window 27.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	scrollx = CreateWindowEx(info[24].dwExStyle, 
				   "SCROLLBAR", 
				   info[24].lpWindowName, 
				   info[24].dwStyle, 
				   0,0,0,0, 
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (scrollx == NULL){
		MessageBox (NULL, "ERROR : Could not create window 28.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	scrolly = CreateWindowEx(info[25].dwExStyle, 
				   "Scrollbar", 
				   info[25].lpWindowName, 
				   WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN,
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL); 
	if (scrolly == NULL){
		MessageBox (NULL, "ERROR : Could not create window 34.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	scrollzbox = CreateWindowEx(info[30].dwExStyle, 
				   info[30].lpszClassName, 
				   info[30].lpWindowName, 
				   info[30].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (scrollzbox == NULL){
		MessageBox (NULL, "ERROR : Could not create window 30.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	scrollz = CreateWindowEx(info[26].dwExStyle, 
				   "Scrollbar", 
				   info[26].lpWindowName, 
				   WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN, 
				   0,0,0,0,
				   scrollzbox,
				   NULL,
				   globalinst,
				   NULL);
	if (scrollz == NULL){
		MessageBox (NULL, "ERROR : Could not create window 34.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	scrollxlabel = CreateWindowEx(info[27].dwExStyle, 
				   info[27].lpszClassName, 
				   info[27].lpWindowName, 
				   info[27].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (scrollxlabel == NULL){
		MessageBox (NULL, "ERROR : Could not create window 34.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	scrollylabel = CreateWindowEx(info[28].dwExStyle, 
				   info[28].lpszClassName, 
				   info[28].lpWindowName, 
				   info[28].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (scrollylabel == NULL){
		MessageBox (NULL, "ERROR : Could not create window 35.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	scrollzlabel = CreateWindowEx(info[29].dwExStyle, 
				   info[29].lpszClassName, 
				   info[29].lpWindowName, 
				   info[29].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (scrollzlabel == NULL){
		MessageBox (NULL, "ERROR : Could not create window 29.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	displaylabel = CreateWindowEx(info[31].dwExStyle, 
				   info[31].lpszClassName, 
				   info[31].lpWindowName, 
				   info[31].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (displaylabel == NULL){
		MessageBox (NULL, "ERROR : Could not create window 31.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	displaytoggle = CreateWindowEx(info[32].dwExStyle, 
				   "BUTTON", 
				   info[32].lpWindowName, 
				   info[32].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[32].hMenu,
				   globalinst, 
				   info[32].lpParam); 
	if (displaytoggle == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	workinglabel = CreateWindowEx(info[33].dwExStyle, 
				   info[33].lpszClassName, 
				   info[33].lpWindowName, 
				   info[33].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (workinglabel == NULL){
		MessageBox (NULL, "ERROR : Could not create window 33.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt4_status = CreateWindowEx(info[34].dwExStyle, 
				   info[34].lpszClassName, 
				   info[34].lpWindowName, 
				   info[34].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (opt4_status == NULL){
		MessageBox (NULL, "ERROR : Could not create window 34.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt4_button = CreateWindowEx(info[35].dwExStyle, 
				   "BUTTON", 
				   info[35].lpWindowName, 
				   info[35].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[35].hMenu,
				   globalinst, 
				   info[35].lpParam); 
	if (opt4_button == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	dropimage = CreateWindowEx(info[36].dwExStyle, 
				   "BUTTON", 
				   info[36].lpWindowName, 
				   info[36].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[36].hMenu,
				   globalinst, 
				   info[36].lpParam); 
	if (dropimage == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	compare_button = CreateWindowEx(info[37].dwExStyle, 
				   "BUTTON", 
				   info[37].lpWindowName, 
				   info[37].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[37].hMenu,
				   globalinst, 
				   info[37].lpParam); 
	if (compare_button == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	compare_photo = CreateWindowEx(info[38].dwExStyle, 
				   "BUTTON", 
				   info[38].lpWindowName, 
				   info[38].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[38].hMenu,
				   globalinst, 
				   info[38].lpParam); 
	if (compare_photo == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	compare_value = CreateWindowEx(info[39].dwExStyle, 
				   info[39].lpszClassName, 
				   info[39].lpWindowName, 
				   info[39].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (compare_value == NULL){
		MessageBox (NULL, "ERROR : Could not create window 39.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	up = CreateWindowEx(info[40].dwExStyle, 
				   "BUTTON", 
				   info[40].lpWindowName, 
				   info[40].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[40].hMenu,
				   globalinst, 
				   info[40].lpParam); 
	if (up == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	down = CreateWindowEx(info[41].dwExStyle, 
				   "BUTTON", 
				   info[41].lpWindowName, 
				   info[41].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[41].hMenu,
				   globalinst, 
				   info[41].lpParam); 
	if (down == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}
	opt5_button = CreateWindowEx(info[42].dwExStyle, 
				   "BUTTON", 
				   info[42].lpWindowName, 
				   info[42].dwStyle, 
				   0,0,0,0, 
				   right_window, 
				   info[42].hMenu,
				   globalinst, 
				   info[42].lpParam); 
	if (opt5_button == NULL){
		MessageBox (NULL, "ERROR : Could not create window 23.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}

	opt5_status = CreateWindowEx(info[43].dwExStyle, 
				   info[43].lpszClassName, 
				   info[43].lpWindowName, 
				   info[43].dwStyle, 
				   0,0,0,0,
				   right_window,
				   NULL,
				   globalinst,
				   NULL);
	if (opt5_status == NULL){
		MessageBox (NULL, "ERROR : Could not create window 43.", "Critical Error", MB_ICONSTOP) ;
		return (1) ;
	}
	
	resetScroll();
	return 0;
}
